﻿Public Class FormArtistDisplay
	Public prevForm As Form
	Dim responseGetInfo As ArtistGetInfoResponse

	Public Function LoadArtist(ByVal name As String, ByVal mbid As String) As Boolean
		Dim methodArtistGetInfo = New ArtistGetInfo(name, mbid, "", "")
		methodArtistGetInfo.sendRequest()

		responseGetInfo = methodArtistGetInfo.getResponse()

		If Not IsNothing(responseGetInfo) Then
			If Not IsNothing(responseGetInfo.artist.image) Then
				If responseGetInfo.artist.image(2) <> Nothing Then
					PictureBoxImageArt.ImageLocation = responseGetInfo.artist.image(2)
				Else
					PictureBoxImageArt.Image = My.Resources.image_unavailable01
				End If
			Else
				PictureBoxImageArt.Image = My.Resources.image_unavailable01
			End If

			LabelArtist.Text = responseGetInfo.artist.name
			LabelPlayCount.Text = responseGetInfo.artist.stats.plays
			LabelListeners.Text = responseGetInfo.artist.stats.listeners
			LinkLabelURL.Text = responseGetInfo.artist.url

			RichTextBoxContent.Rtf = ""
			RichTextBoxContent.Text = responseGetInfo.artist.bio.content
			RichTextBoxContent.Rtf = RichTextBoxContent.Rtf.Replace("&quot;", """")
			RichTextBoxContent.Rtf = RichTextBoxContent.Rtf.Replace("<em>", "")
			RichTextBoxContent.Rtf = RichTextBoxContent.Rtf.Replace("</em>", "")
			RichTextBoxContent.Rtf = RichTextBoxContent.Rtf.Replace("</strong>", "")
			RichTextBoxContent.Rtf = RichTextBoxContent.Rtf.Replace("<strong>", "")


			RichTextBoxContent.Text = RichTextBoxContent.Text.Replace("</a>", "")

			Dim pos1 = Strings.InStr(RichTextBoxContent.Text, "<a ")
			Do While (pos1 <> 0)
				Dim pos2 = Strings.InStr(RichTextBoxContent.Text, ">")
				RichTextBoxContent.Text = RichTextBoxContent.Text.Remove(pos1 - 1, pos2 - pos1 + 1)
				pos1 = Strings.InStr(RichTextBoxContent.Text, "<a ")
			Loop


			ModuleControls.GenerateListViewSearch(ListViewSimilar)
			ModuleArtist.AddToListView(responseGetInfo.artist.similar, ListViewSimilar)
			ModuleTags.AddToListView(responseGetInfo.artist.tags, ListViewTags)
		Else
			Return False
		End If









		Dim methodGetShouts = New ArtistGetShouts(name, "", "", 10, 1)
		methodGetShouts.sendRequest()
		Dim response2 = methodGetShouts.getResponse()

		If Not IsNothing(response2) Then
			ModuleShout.GenerateShouts(response2.shouts, FlowLayoutPanel1)
		End If




		'Dim methodGetSimilar = New ArtistGetSimilar(name, mbid, "", "")
		'methodGetSimilar.sendRequest()
		'Dim response3 = methodGetSimilar.getResponse()

		'If Not IsNothing(response3) Then
		'ModuleControls.GenerateListViewSearch(ListViewSimilar)
		'ModuleArtist.AddToListView(response.artist.similar, ListViewSimilar)

		'End If




		Return True
	End Function

	Private Sub FormAlbumDisplay_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		If Not IsNothing(prevForm) Then
			prevForm.Show()
			prevForm = Nothing
		End If
	End Sub

	Private Sub FormArtistDisplay_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

	End Sub

	Private Sub ButtonGoBack_Click_1(sender As System.Object, e As System.EventArgs) Handles ButtonGoBack.Click
		prevForm.Show()
		Me.Close()

	End Sub

	Private Sub ListViewSimilar_ItemActivate(sender As Object, e As System.EventArgs) Handles ListViewSimilar.ItemActivate
		LoadArtist(ListViewSimilar.SelectedItems.Item(0).SubItems("Artist Name").Text, ListViewSimilar.SelectedItems.Item(0).SubItems("MBID").Text)
	End Sub
End Class